Completed
Push — master ( d0979c...22246f )
by Sander
49s
created

sharingAcl.js ➔ SharingACL   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
function SharingACL (acl_permission) {
2
    this.permission = acl_permission;
3
}
4
5
SharingACL.prototype.permissions = {
6
    READ: 0x01,
7
    WRITE: 0x02,
8
    FILES: 0x04,
9
    HISTORY: 0x08,
10
    OWNER: 0x80,
11
};
12
/**
13
 * Checks if a user has the given permission/s
14
 * @param permission
15
 * @returns {boolean}
16
 */
17
SharingACL.prototype.hasPermission = function (permission) {
18
    return permission === (this.permission & permission);
19
};
20
21
/**
22
 * Adds a permission to a user, leaving any other permissions intact
23
 * @param permission
24
 */
25
SharingACL.prototype.addPermission = function (permission) {
26
    this.permission = this.permission | permission;
27
};
28
29
/**
30
 * Removes a given permission from the item, leaving any other intact
31
 * @param permission
32
 */
33
SharingACL.prototype.removePermission = function (permission) {
34
    this.permission = this.permission & ~permission;
35
};
36
37
SharingACL.prototype.togglePermission = function (permission) {
38
    this.permission ^= permission;
39
};
40
41
SharingACL.prototype.getAccessLevel = function () {
42
    return this.permission;
43
};